﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WsusWebAdmin.Web.Helpers
{
    public static class IntExtensions
    {
        private const int BorderValue = 700;

        public static string AsSize(this Int64 number)
        {
            string unit = "bytes";
            
            double value = (double)number;
            if (value>=BorderValue)
            {
                unit = "KB";
                value = value / 1024;

                if (value >= BorderValue)
                {
                    unit = "MB";
                    value = value / 1024;

                    if (value >= BorderValue)
                    {
                        unit = "GB";
                        value = value / 1024;
                    }
                }
            }

            return string.Format("{0:N2} {1}", value, unit);
        }
    }
}